<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>医院药品管理系统</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/admin/style.css}" media="all">
    <link rel="stylesheet" th:href="@{/layui/css/element-index.css}" media="all">
</head>
<body class="layui-layout-body">
<!--顶部-->
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">医院药品管理系统</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layuimini-setting">
                <a href="javascript:;"><span th:text="${session.user.role}"></span></a>
                <dl class="layui-nav-child">
                    <dd>
                        <a href="javascript:;" id="deleteAccount" data-title="注销" data-icon="fa fa-gears">注销</a>
                    </dd>
                    <dd>
                        <hr>
                    </dd>
                    <dd>
                        <a href="/logout" class="login-out">退出登录</a>
                    </dd>
                </dl>
            </li>
        </ul>
    </div>
    <!--左侧菜单-->
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree" lay-accordion="true">
                <li class="layui-nav-item">
                    <a href="javascript:;" class="layui-nav-item">药品人员管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="#" class="site-demo-active" lay-href="/employee" data-id="12" data-title="员工信息">员工信息</a></dd>
                        <dd><a href="#" class="site-demo-active" lay-href="/customer" data-id="13" data-title="客户信息">客户信息</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;" class="layui-nav-item">药品销售管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="#" class="site-demo-active" lay-href="/purchaseRecords" data-id="21" data-title="进货记录">进货记录</a></dd>
                        <dd><a href="#" class="site-demo-active" lay-href="/salesRecords" data-id="22" data-title="销售记录">销售记录</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;" class="layui-nav-item">药品明细管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="#" class="site-demo-active" lay-href="/drug" data-id="31" data-title="药品信息">药品信息</a></dd>
                        <dd><a href="#" class="site-demo-active" lay-href="/supplier" data-id="32" data-title="供应商信息">供应商信息</a></dd>
                        <dd><a href="#" class="site-demo-active" lay-href="/loss" data-id="33" data-title="药品损失信息">药品损失信息</a></dd>
                        <dd><a href="#" class="site-demo-active" lay-href="/checklist" data-id="34" data-title="出入库信息">出入库信息</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
    <!--主体部分-->
    <div class="layui-body">
        <div class="layui-tab" lay-filter="demo" lay-allowclose="true" style="margin: 0;">
            <ul class="layui-tab-title"></ul>
            <div class="layui-tab-content"></div>
        </div>
    </div>
    <!--底部区域-->
</div>

<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/layui/lay/modules/jquery.js}"></script>
<script th:src="@{/layui/lay/modules/table.js}"></script>
<script th:src="@{/layui/lay/modules/element-index.js}"></script>
<script>
    layui.use(['element','layer','jquery'],function () {
        var element = layui.element;
        var $ = layui.$;

        // 左侧菜单树叶点击事件
        $('.site-demo-active').on('click',function () {
            var dataid = $(this);
            if ($(".layui-tab-title li[lay-id]").length <=0 ){
                active.tabAdd(dataid.attr('lay-href'),dataid.attr('data-id'),dataid.attr('data-title'));
            } else {
                var isExist = false;
                $.each($(".layui-tab-title li[lay-id]"),function () {
                    if ($(this).attr("lay-id") == dataid.attr("data-id")){
                        isExist = true;
                    }
                });
                if (!isExist){
                    active.tabAdd(dataid.attr('lay-href'),dataid.attr('data-id'),dataid.attr('data-title'));
                }
            }
            active.tabChange(dataid.attr("data-id"));
        });

        var active = {
            tabAdd: function (url, id, name) {
                element.tabAdd('demo', {
                    title: name,
                    content: '<iframe data-frameid="'+id+'" scrolling="auto" frameborder="0" src="'+url+'" style="width: 100%;height: 800px;"></iframe>',
                    id: id
                });
            },
            tabChange: function (id) {
                element.tabChange('demo', id);
            },
            tabDelete: function (id) {
                element.tabDelete('demo', id);
            }
        }

        $(document).ready(function () {
            $('#deleteAccount').on('click', function (e) {
                e.preventDefault();
                if (confirm('确定要注销您的账户吗？')) {
                    $.ajax({
                        type: 'GET',
                        url: '/deleteAccount',
                        success: function (response) {
                            window.location.href = '/login';
                        },
                        error: function (xhr, status, error) {
                            alert('注销账户时发生错误，请重试。');
                        }
                    });
                }
            });
            $('#profile').on('click', function () {
                window.location.href = '/profile';
            });
        });
    });
</script>
</body>
</html>
